package com.example.springbootelasticsearch.controller;

import com.example.springbootelasticsearch.pojo.Content;
import com.example.springbootelasticsearch.service.ContentService;
import com.example.springbootelasticsearch.uitl.HtmlParseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class HelloController {

    @Autowired
    private ContentService contentService;
    @Autowired
    private HtmlParseUtil htmlParseUtil;

    @GetMapping({"/", "/index"})
    public String index() {
        return "index";
    }

    @GetMapping("/search/{keyword}")
    @ResponseBody
    public Object search(@PathVariable("keyword") String keyword) throws IOException {
        return contentService.searchPage(keyword, 0, 100);
    }
}
